package com.atguigu.day03;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

public class Flink06_Transfrom_Union {
    public static void main(String[] args) throws Exception {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //2.分别获取两个流
        DataStreamSource<String> intStream = env.fromElements("1", "2", "3", "4", "5");
        DataStreamSource<String> strStream = env.fromElements("a", "b", "c", "d");

        //TODO 3.使用Union合并两条流  注意！！！ 连接的多个流类型必须一致 还可以合并多个流
        DataStream<String> union = intStream.union(strStream);
        SingleOutputStreamOperator<String> map = union.map(new MapFunction<String, String>() {
            @Override
            public String map(String value) throws Exception {
                return value + "1111111";
            }
        });

        map.print();

        env.execute();

    }
}
